<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <!--引入Vue-->
  <script type="text/javascript" src="../js/vue.js"></script>
  <style>
    .basic{
      width: 400px;
      height: 200px;
      border: 1px solid black;
    }
    .normal{
      background-color: #3A71A8;
    }
    .happy{
      background-color: orange;
    }
    .sad{
      background-color: green;
    }
    .st1{
      font-size: 24px;
    }
    .st2{
      color: rebeccapurple;
    }
    .st3{
      font-weight: bold;
    }
  </style>
</head>
<body>
<div class="root">
<!--  变化的样式用了:class-->
<!--  绑定class样式,字符串写法,适用于样式的类型不确定,需要动态指定-->
  <div class="basic" :class="mood" @click="changeMood">{{name}}</div><br/><br/>
  <!--  绑定class样式,数组写法,适用于要绑定的样式个数不确定,名字也不确定-->
  <div class="basic" :class="arr" @click="changeMood">{{name}}</div><br/><br/>
  <!--  绑定class样式,对象写法,适用于要绑定的样式个数确定,名字也确定,但是要动态决定是否使用-->
  <div class="basic" :class="obj" @click="changeMood">{{name}}</div><br/><br/>
</div>
</body>

<script type="text/javascript">
  new Vue({
    el: '.root',
    data: {
      name: 'Jack',
      mood: 'normal',
      arr: ['st1'],
      obj: {
        st1: false,
        st2: true
      }
    },
    methods:{
      changeMood(){
        const arr = ['happy','sad','normal']
        let index = Math.floor(Math.random()*3)
        this.mood = arr[index]
        console.log(this.mood)
      }
    }
  })
</script>
</html>
